home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE18 / TIPTRIX / DSTART.DPR < prev    next >
Encoding:
Text File  |  1997-01-17  |  3.5 KB  |  140 lines

  1. program Dstart;
  2.  
  3. {$R *.res}
  4.  
  5. uses Classes, WinTypes, WinProcs, Messages, SysUtils;
  6. var
  7.   SearchRec  : TSearchRec;
  8.   PopupMenu  : HMenu;
  9.   Msg        : TMSG;
  10.   ReturnValue: integer;
  11.   ret        : integer;
  12.   cpos       : TPOINT;
  13.   iptr       : PChar;
  14.   buf        : array [0..255] of char;
  15.   noch       : integer;
  16.   flags      : word;
  17.   i,x,y      : integer;
  18.   hHookedWnd : HWND;
  19.   tmpstr     : string;
  20.   startdir   : string;
  21.   curDCL     : string;
  22.   files      : TStringList;
  23.   dStartClass: array [0..255] of char;
  24.  
  25. function NewMsgHandler(Window : HWnd; Message : Word;
  26.                        wParam : Word; lParam : LongInt) : LongInt; export;
  27. begin
  28.  
  29.   case Message of
  30.     wm_Command     : begin
  31.       case WParam of
  32.         1..20: ReturnValue := WParam;
  33.       end;
  34.     end;
  35.   end;
  36. end;
  37.  
  38. function QuickWindow:HWND;
  39. var
  40. wc     : TWNDCLASS;
  41.  
  42. begin
  43. { Register the window class. }
  44. StrPCopy(dStartClass,'Delphi Start');
  45. wc.style         := 0;
  46. wc.lpfnWndProc   := @NewMsgHandler;
  47. wc.cbClsExtra    := 0;
  48. wc.cbWndExtra    := 0;
  49. wc.hInstance     := hInstance;
  50. wc.hIcon         := 0;
  51. wc.hCursor       := LoadCursor(0,IDC_ARROW);
  52. wc.hbrBackground := 0;
  53. wc.lpszMenuName  := nil;
  54.  
  55. wc.lpszClassName := dStartClass;
  56.  
  57. if RegisterClass(wc) then
  58.     QuickWindow := CreateWindow(dStartClass, 'Delphi Start',
  59.         WS_OVERLAPPED or WS_SYSMENU, CW_USEDEFAULT, 0,
  60.         CW_USEDEFAULT, 0, 0, 0,
  61.         hInstance, nil );
  62.  
  63. end;
  64.  
  65. begin
  66.   getdir(0,StartDir);               {record start dir, i.e. working directory of
  67. pm icon}
  68.   ReturnValue := 0;
  69.  
  70.   GetCursorPos(cpos);
  71.   x := cpos.x;
  72.   y := cpos.y;
  73.  
  74.   hHookedWnd := QuickWindow;      {create invisible window to receive messages}
  75.  
  76.   i:=0;
  77.   flags := 0;
  78.  
  79.   {load current component library setting, and get directory part of it by
  80. setting
  81.   last \ to 0}
  82.   ret :=
  83. GetPrivateProfileString('Library','ComponentLibrary','',buf,225,'DELPHI.INI');
  84.   iptr := StrRScan(buf,'\');
  85.   iptr[0] := chr(0);
  86.   tmpstr := StrPas(buf);
  87.   iptr := iptr+1;
  88.   curDCL := StrPas(iptr);
  89.  
  90.  
  91.   files := TStringList.Create;
  92.   PopupMenu := CreatePopupMenu;
  93.   AppendMenu(PopupMenu,mf_disabled,0,buf);
  94.  
  95.   {Change directory to component library dir and list all files in the directory
  96.   For each file, add to menu and a string list - the latter for use later if a
  97.   menu item is chosen}
  98.   chdir(tmpstr);
  99.   ret := FindFirst('*.DCL',faAnyFile , SearchRec);
  100.   while ret = 0 do begin
  101.     StrPCopy(buf,SearchRec.Name);
  102.     files.add(SearchRec.Name);
  103.     i:= i + 1;
  104.     if SearchRec.Name = curDCL then
  105.         flags := mf_checked
  106.     else
  107.         flags := 0;
  108.  
  109.     AppendMenu(PopupMenu,flags,i,buf);
  110.     ret := FindNext(SearchRec);
  111.   end;
  112.  
  113.   {..and display the menu}
  114.   TrackPopupMenu(PopupMenu,0,x,y,0,hHookedWnd,nil);
  115.  
  116.   {Check for whether a menu selection was made}
  117.   if PeekMessage(Msg,hHookedWnd,0,32767,PM_REMOVE) then
  118.       DispatchMessage(Msg);
  119.  
  120.   {get rid of window created by QuickWindow}
  121.   DestroyWindow(hHookedWnd);
  122.   UnregisterClass(dStartClass,hInstance);
  123.  
  124.   {only process anything if return value > 0 i.e. a menu item has been chosen}
  125.   if ReturnValue > 0 then begin
  126.     getdir(0,tmpstr);
  127.     tmpstr := tmpstr + '\' + files[ReturnValue - 1];
  128.     StrPCopy(buf,tmpstr);
  129.     WritePrivateProfileString('Library','ComponentLibrary',buf,'DELPHI.INI');
  130.     getdir(0,tmpstr);
  131.     tmpstr := tmpstr + '\DELPHI.EXE ';
  132.     StrPCopy(buf,tmpstr);
  133.     StrCat(buf, cmdLine);
  134.     chdir(StartDir);
  135.     WinExec(buf,cmdShow);
  136.   end;
  137.  
  138.  
  139. end.
  140.